package logic

import (
	"MyBlogv2/blog-common/HttpCode"
	"MyBlogv2/blog-common/models"
	"context"
	"github.com/jinzhu/copier"

	"MyBlogv2/Servers/UserAction/internal/svc"
	"MyBlogv2/Servers/UserAction/userAction"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateUserInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserInfoLogic {
	return &UpdateUserInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateUserInfoLogic) UpdateUserInfo(in *UserAction.UpdateUserInfoRequest) (*UserAction.CommonResponse, error) {
	userId := int(in.UserId)
	var userUpdateDto models.UserUpdateDto
	copier.Copy(&userUpdateDto, &in.UserUpdateDto)
	models.Db.Model(new(models.User)).Where("id = ?", userId).Updates(userUpdateDto)
	return &UserAction.CommonResponse{
		Code: int64(HttpCode.SUCCESS),
	}, nil

}
